﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AppiSynchro.Library.Helpers
{
    public class WebDavHelper
    {
        public static bool GetDirectoryFiles(String user, String pass, String url, String localPath, String extension)
        {
            WebDav.WebDav webdav = new WebDav.WebDav(user, pass);
            List<WebDav.WebDav.Entity> entities = webdav.BrowseDirectory(url);
            if (entities == null)
                return false;

            foreach (WebDav.WebDav.Entity ent in entities)
            {
                if (ent.IsDirectory)
                    continue;
                if (!String.IsNullOrEmpty(extension))
                    if (!ent.FileName.EndsWith(extension))
                        continue;

                webdav.Download(ent, localPath);
            }

            return true;
        }
    }
}
